package com.jdk.mode.relate;

/**
 * @author jukg
 * @date 2023/08/28 14:41
 * @description 模板模式 父类虚拟类，固定好方法实现逻辑，子类负责具体逻辑方法的实现
 */
public class TemplateTest {

    public static void main(String[] args) {
        Template t = new T1("t1");
        t.run();

        Template t2 = new T2("t2");
        t2.run();
    }
}

abstract class Template{

    private String name;

    public Template(String name) {
        this.name = name;
    }

    void run(){
        prepared();
        doing();
        finished();
    }

    String getName(){
        return name;
    }

    abstract void prepared();

    abstract void doing();

    abstract void finished();
}

class T1 extends Template{


    public T1(String name) {
        super(name);
    }

    @Override
    void prepared() {
        System.out.println(super.getName() + "prepared");
    }

    @Override
    void doing() {
        System.out.println(super.getName() + "doing");
    }

    @Override
    void finished() {
        System.out.println(super.getName() + "finished");
    }
}

class T2 extends Template{

    public T2(String name) {
        super(name);
    }

    @Override
    void prepared() {
        System.out.println(super.getName() + "prepared");
    }

    @Override
    void doing() {
        System.out.println(super.getName() + "doing");
    }

    @Override
    void finished() {
        System.out.println(super.getName() + "finished");
    }
}
